//
//  HMStatusCell.m
//  OC新浪微博
//
//  Created by wyman on 16/4/16.
//  Copyright © 2016年 wyman. All rights reserved.
//

#import "HMStatusCell.h"
#import "HMStatusOriginView.h"
#import <Masonry.h>
#import "HMStatusBottomView.h"
#import "HMReetweetView.h"
@interface HMStatusCell()
@property (nonatomic, strong) HMStatusBottomView *bottomView;
@property (nonatomic, strong) HMStatusOriginView *oringinView;
@property (nonatomic, strong) HMReetweetView *retWeetView;

@property (nonatomic, strong) MASConstraint *bottomTop;

@end

@implementation HMStatusCell

-(void)setStatus:(HMStatu *)status{

    _status = status;
    self.oringinView.status = status;
    
//    self.bottomView
    [self.bottomTop uninstall];

    //赋值给转发微博
    if (status.retweeted_status) {
        self.retWeetView.hidden = NO;
        self.retWeetView.retweet = status.retweeted_status;

        [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
           self.bottomTop = make.top.equalTo(self.retWeetView.mas_bottom);
            
        }];
      
        
    }else{
    
        self.retWeetView.hidden = YES;
        
        [ self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            self.bottomTop = make.top.equalTo(self.oringinView.mas_bottom);
            
        }];
    
    }
    
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self prepare];
//        self.backgroundColor = [UIColor colorWithRed:((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0];
    }
    self.backgroundColor = [[UIColor alloc]initWithWhite:237.0/255.0 alpha:1];
//    self.contentView.backgroundColor = [UIColor whiteColor];
    return self;
}

-(void)prepare
{
    
    [self.contentView addSubview:self.oringinView];

    [self.contentView addSubview:self.bottomView];
    
    [self.contentView addSubview:self.retWeetView];
    //约束
    [self.oringinView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(10);
    }];
  
  
    
    [self.retWeetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.contentView);
        make.top.equalTo(self.oringinView.mas_bottom);
        
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.contentView);
       self.bottomTop =   make.top.equalTo(self.retWeetView.mas_bottom);
        make.height.mas_equalTo(37);
        
    }];
    //给contentView设置farame
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self);
        make.bottom.equalTo(self.bottomView);
    }];



}

-(HMStatusBottomView *)bottomView
{
    if (_bottomView == nil) {
        _bottomView = [[HMStatusBottomView alloc]init];
        
    }
    return _bottomView;

}

-(HMStatusOriginView *)oringinView
{
    if (_oringinView == nil) {
        _oringinView = [[HMStatusOriginView alloc]init];
    }
    return _oringinView;

}

-(HMReetweetView *)retWeetView{
    if (_retWeetView == nil) {
        _retWeetView = [[HMReetweetView alloc]init];
    }
    return _retWeetView;

}
@end
